package com.shunde.xunjian.controller;

import com.shunde.xunjian.service.impl.ComplaintRegistrationServiceImpl;
import com.shunde.xunjian.service.impl.ReportOrdersServiceImpl;
import com.shunde.xunjian.service.impl.VerificationReportServiceImpl;
import com.shunde.xunjian.util.Results;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

import java.text.ParseException;

@RestController
@RequestMapping("/AppXunJian")
public class AppXunJianController {
    @Autowired
    private ComplaintRegistrationServiceImpl complaintRegistrationService;

    @Autowired
    private VerificationReportServiceImpl verificationReportService;

    @Autowired
    private ReportOrdersServiceImpl reportOrdersService;

    //APP巡检投诉台账
    @RequestMapping(value = "/queryComplaints", method = RequestMethod.POST)
    public Object ComplaintRegistrationResults(String complaintRegistrationStr, @RequestParam(value = "current", defaultValue = "1") Integer current, @RequestParam(value = "pageSize", defaultValue = "10") Integer pageSize) throws ParseException {
        return Results.success(complaintRegistrationService.queryComplaints(complaintRegistrationStr, current, pageSize));
    }

    //APP核查上报
    @RequestMapping(value = "/verificationUpload", method = RequestMethod.POST)
    public Object VerificationUpload(String verificationReportStr) {
        if (verificationReportStr != null && !verificationReportStr.equals("{}")) {
            if (verificationReportService.VerificationUpload(verificationReportStr) == 1) {
                return Results.success("核查上报成功");
            } else {
                return Results.error("核查上报失败");
            }
        } else {
            return Results.error("核查上报失败");
        }
    }

    //工单上报
    @RequestMapping(value = "/ReportOrdersUpload", method = RequestMethod.POST)
    public Object ReportOrdersUpload(String reportOrdersStr) throws ParseException {
        if (reportOrdersStr != null && !reportOrdersStr.equals("{}")) {
            if (reportOrdersService.ReportOrdersUpload(reportOrdersStr) == 1) {
                return Results.success("工单上报成功");
            } else {
                return Results.error("工单上报失败");
            }
        } else {
            return Results.error("工单上报失败");
        }
    }

    //APP处理工单
    @RequestMapping(value = "/dealReportOrdersUpload", method = RequestMethod.POST)
    public Object dealReportOrdersUpload(String reportOrdersStr) {
        if (reportOrdersStr != null && !reportOrdersStr.equals("{}")) {
            if (reportOrdersService.dealReportOrdersUpload(reportOrdersStr) == 1) {
                return Results.success("处理工单成功");
            } else {
                return Results.error("处理工单失败");
            }
        } else {
            return Results.error("处理工单失败");
        }
    }

    //APP投诉核查、维修、清疏工单数量
    @RequestMapping(value = "/appOrderNums", method = RequestMethod.POST)
    public Object appOrderNums(String reportOrdersStrMatinance,String reportOrdersStrClean, String complaintRegistrationStr) {
        return Results.success(reportOrdersService.appOrderNums(reportOrdersStrMatinance, reportOrdersStrClean, complaintRegistrationStr));
    }

}
